package com.education.service.impl;

import com.education.dao.HistoryScoreMapper;
import com.education.dao.QuestionMapper;
import com.education.dao.TestPaperMapper;
import com.education.dao.UserErrorMapper;
import com.education.pojo.HistoryScore;
import com.education.pojo.Question;
import com.education.pojo.UserError;
import com.education.service.WZJService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/4/28.
 */
@Service
public class WZJServiceImpl implements WZJService{
    /**
     * 注入导层
     */
    @Autowired
    private QuestionMapper questionMapper;//问题类导层

    @Autowired
    private HistoryScoreMapper historyScoreMapper;//历史成绩类导层

    @Autowired
    private UserErrorMapper userErrorMapper;//用户回答错误类导层

    @Autowired
    private TestPaperMapper testPaperMapper;//试卷类导层

    /**
     *
     * @param tpId
     * @return
     * 问题类的方法调用区
     */

    //(吴)根据试卷的Id查询数据库中对应试卷的题，将该数据吐到前台页面
    @Override
    public List<Question> queryQuestionListPage(Integer tpId) {
        return questionMapper.selectQuestionListPage(tpId);
    }
    // (吴)根据题目ID 查询正确答案
    @Override
    public List<Question> queryQuestionAnswerList(Integer tpId) {
        return  questionMapper.selectQuestionAnswerList(tpId);
    }

    /**
     * (吴)根据用户回答错误题目的ID 查询试卷的Tpid
     */
    @Override
    public Integer queryUserErrorTpidList(Integer qId) {
        return questionMapper.selectUserErrorTpidList(qId);
    }


    /**
     *
     * @param record
     * @return
     * 历史成绩类方法调用区
     */

    @Override
    public int addHistoryScoreMessage(HistoryScore record) {
        return  historyScoreMapper.insertHistoryScoreMessage(record);
    }

    @Override
    public List<HistoryScore> queryUserHistoryScore(Integer uId) {
        return historyScoreMapper.selectUserHistoryScore(uId);
    }

    /**
     *
     * @param record
     * @return
     * 用户回答错误类方法调用区
     */
    @Override
    public int addUserErrorMessage(UserError record) {

        return userErrorMapper.insertUserErrorMessage(record);
    }



    @Override
//    public List<UserError> queryUserErrorQidMessage(Integer uId) {
//        return userErrorMapper.selectUserErrorQidMessage(uId);
//    }
    public List<UserError> queryUserErrorQidMessage(@Param("uId") Integer uId, @Param("ueCreateTime")String ueCreateTime) {
        return userErrorMapper.selectUserErrorQidMessage(uId,ueCreateTime);
    }

    //根据QID查询用户历史错误题中是否已经存在该错题，如果存在就将最新的错误跟新以前的错题
    @Override
    public Integer queryUserErrorHistoryQidMessage(Integer qId,Integer uId) {
        return userErrorMapper.selectUserErrorHistoryQidMessage(qId,uId);
    }

//    public Integer queryUserErrorHistoryQidMessage(Map map){
//        return userErrorMapper.selectUserErrorHistoryQidMessage(map);
//    }
    //更新用户的历史错题的信息
    @Override
    public Integer modifyUserErrorHistoryQidMessage(UserError userError) {
        return userErrorMapper.updateUserErrorHistoryQidMessage(userError);
    }

    /**
     * 根据试卷ID 获得书卷名称
     */
    @Override
    public String queryUserErrorTpNameList(Integer tpId) {
        return testPaperMapper.selectUserErrorTpNameList(tpId);
    }

    /*
      根据用户TPID查询本试卷的QID，将查询到的QID用到错误库中去比对，是否有该错题，有就显示
    */

    @Override
    public List<Integer> queryQidUseUserErrorQidList(Integer tpId) {
        return questionMapper.selectQidUseUserErrorQidList(tpId);
    }
  /*
    根据q_id查询该试卷的错误题的用户的答案ue_answer
     */

    @Override
    public String queryUeAnswerOneMessage(@Param("qId") Integer qId, @Param("uId") Integer uId,@Param("ueCreateTime")String ueCreateTime) {
        return userErrorMapper.selectUeAnswerOneMessage(qId,uId,ueCreateTime);
    }

       /*
错题展示题，根据用户错误题的qid查询表中q_id, q_name, q_order, q_answer，q_answer_true等字段
 */

    @Override
    public Question queryUserErrorQuestionListMessage(Integer qId) {
        return questionMapper.selectUserErrorQuestionListMessage(qId);
    }
}
